const jwt = require('jsonwebtoken')
module.exports = (option,app) => {
    return async function Auth(ctx,next) {
        const {authorization} = ctx.request.header;
        if(authorization) {
            console.log(authorization);
            const token = authorization.split(' ')[1];
           try{
            const data= jwt.verify(token, ctx.app.config.keys);
            await next();
           }catch(err) {
               ctx.status =401;
               ctx.body = '鉴权失败'+err.message;
           }
        } else {
            ctx.status = 401;
            ctx.body = '无权限';
        }
    }
}